<template>
    <el-dialog v-model="dialogFormVisible" :title="title" @close="closeDialog" align-center
        style="width:90%;min-height:90%;">
        <div class="app-body">
            <div class="app-search">
                <el-form :inline="true" class="demo-form-inline" v-model="form">
                    <el-form-item label="资产名称">
                        <el-input placeholder="请输入资产名称" style="width: 200px;" v-model="form.name"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button class="serach_btn" type="primary" @click="onSubmit"
                            @keyup.enter="searchEnter">搜索</el-button>
                        <el-button class="export_btn" type="success" @click="exportHandle">导出</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <el-table :data="list" style="width: 100%" @selection-change="selectAll">
                <!-- <el-table-column type="selection" width="30" @select-all="selectAll1" /> -->
                <el-table-column prop="id" label="id" width="80" />
                <el-table-column prop="name" label="资产名称" width="150" />
                <el-table-column prop="purchaseDate" label="购进日期" width="110" />
                <el-table-column prop="department" label="使用部门" width="150" />
                <el-table-column prop="useTeacher" label="使用人" width="150" />
                <el-table-column prop="campus" label="存放校区" width="150" />
                <el-table-column prop="place" label="存放地点" width="180" />
                <el-table-column prop="brand" label="品牌" />
                <el-table-column prop="model" label="型号" />
                <el-table-column prop="remark" label="备注" />
                <!-- <el-table-column prop="department" label="使用部门" width="110" /> -->
                <!-- <el-table-column prop="department" label="使用部门" width="170">
                    <template style="display: block" #default="scope">
                        <el-select v-model="scope.row.department" placeholder="请选择管理部门" style="width:100%" filterable
                            :filter-method="serachDepartment" clearable @change="changeDepartment1">
                            <el-option v-for="item in departmentAllList" :key="item.id" :label="item.name"
                                :value="item.id" />
                        </el-select>
                    </template>
</el-table-column>
<el-table-column prop="useTeacher" label="使用人" width="110">
    <template style="display: block" #default="scope">
                        <el-select v-model="scope.row.useTeacher" filterable :filter-method="serachTeacher"
                            placeholder="请选择使用人 " style="width:100%" @change="changeTeacher"
                            @focus="focusHandle(scope.row.useTeacher)">
                            <el-option v-for="item in teacherList" :key="item.id" :label="item.name"
                                :value="item.name" />
                        </el-select>
                    </template>
</el-table-column>
<el-table-column prop="place" label="存放地点" width="200">
    <template style="display: block" #default="scope">
                        <el-cascader :placeholder="getStoreAdress(scope.row.place)" :options="addresslist" filterable
                            v-model="scope.row.place" @change="handleChangePlace" />

                    </template>
</el-table-column>
<el-table-column prop="remark" label="备注" width="220">
    <template style="display: block" #default="scope">
                        <el-input placeholder="请输入备注" v-model="scope.row.remark" />
                    </template>
</el-table-column>
<el-table-column prop="managerDepartment" label="管理部门" width="120">
</el-table-column>

<el-table-column label="存放校区" width="200">
    <template style="display: block" #default="scope">
                        <el-radio-group v-model="scope.row.campus">
                            <el-radio :value="1" :label="1">{{ campusName }}</el-radio>
                            <el-radio :value="2" :label="2">{{ campusName1 }}</el-radio>
                        </el-radio-group>
                    </template>
</el-table-column> -->
                <el-table-column label="操作" width="80px" fixed="right">
                    <template style="display: block" #default="scope">
                        <el-button class="del_btn" size="small" type="error" @click="delHandle(scope.row)">删除
                        </el-button>
                    </template>
                </el-table-column>
                <template v-slot:empty>
                    <el-empty description="暂无数据"></el-empty>
                </template>
            </el-table>

            <el-config-provider :locale="locale" style="margin-top: 10px;">
                <el-pagination :total="total" :page-size="limit" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
                    layout="total, sizes, prev, pager, next, jumper" @size-change="changePageSize"
                    @current-change="changeCurrentPage">
                </el-pagination>
            </el-config-provider>




        </div>
    </el-dialog>
</template>

<script>
import { ref } from "vue";
import { httpService } from "@/utils/httpService";
import { ElMessage, ElForm, ElMessageBox, ElLoading } from "element-plus";
import { vxRule } from "@/utils/validator";
import { formatTime } from "@/utils/dateFormat.js";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { API_BASE_NAME2, API_BASE_NAME3, API_BASE_NAME, API_BASE_NAM1 } from '../../constants';

export default {
    name: "AddBaseAddress",
    components: { ElForm, ElMessage },
    data() {
        return {
            campusName: API_BASE_NAME2,
            campusName1: API_BASE_NAME3,
            dialogFormVisible: ref(false),
            formLabelWidth: "120px",
            title: "",
            personnelType: "",
            id: '',
            campus: 1,
            data: {},
            page: 1,
            pageSize: 10,
            projectId: '',

            total: 0,
            limit: 10,
            list: [],
            user: {},
            form: {
                id: "",
                name: '',
                purchaseDate: "",
                flag: 0,
                useTeacher: "",
                department: "",
            },
            addTaskForm: {
                useTeacher: '',
                place: '',
                campus: '',
                department: '',
            },
            campusOptions: [
                {
                    label: API_BASE_NAME2,
                    value: 1
                },
                {
                    label: API_BASE_NAME3,
                    value: 2
                },
            ]
            // 校验规则
            // addBaseTaskrules: {
            //     name: vxRule(true, null, "blur"),
            // },
        };
    },
    setup() {
        return {
            locale: zhCn,
        };
    },
    mounted() {
        this.user = JSON.parse(sessionStorage.getItem('user'))
    },
    watch: {
        data(newValue) {
            this.addBasePanForm = newValue
        },
    },


    methods: {
        searchEnter: function (e) {
            // 使用 which 和 keyCode 属性来解决兼容问题
            var keyCode = window.event ? e.keyCode : e.which;
            var val = e.target.value;
            if (keyCode == 13 && val) {
                this.getInventoryList(this.id);
            }
        },
        onSubmit() {
            this.getInventoryList(this.id);
        },

        closeDialog() {
            this.clear();
        },
        cancel() {
            this.dialogFormVisible = false;
            this.clear();
        },

        getInventoryList(id) {
            console.log(id);
            httpService("/javaApi/faProjectRemark/list/" + this.page + "/" + this.pageSize, {
                projectId: this.projectId
            }, "get").then(
                (data) => {
                    if (data.list) {
                        data.list.map(item => item.purchaseDate = formatTime(new Date(item.purchaseDate)))
                    }
                    this.list = data.list
                    console.log(this.list);
                }
            );
        },

        clear() {
            this.dialogFormVisible = false;
            //清空form
            this.title = ''
            this.id = ''
            this.list = []
            this.list1 = []
            this.page = 1
            this.page1 = 1
            this.pageSize = 10
        },

        changePageSize(size) {
            this.pageSize = size;
            this.limit = size;
            this.getInventoryList(this.id);
        },
        // 改变页码，page：回调参数，表示当前选中的“页码”
        changeCurrentPage(page) {
            this.page = page;
            this.getInventoryList(this.id);
        },

        delHandle(value) {
            httpService("/javaApi/faProjectRemark/deleteById", "id=" + value.id, "post").then(
                (data) => {
                    console.log(data);
                }
            );
        },
        exportHandle(value) {
            httpService("/javaApi/faProjectRemark/exportExcel", { projectId: this.projectId }, "get").then(
                (data) => {
                    console.log(data);
                    if (data.code == 200) {
                        ElMessage.success("导出成功");
                        window.open(data.message, "_blank")
                        // window.open("http://192.168.9.20" + data.message, "_blank")
                    } else {
                        ElMessage.warning("导出失败");
                    }
                }
            );
        },


    }
};
</script>
<style scoped>
.el-table {
    margin-bottom: 20px;
}

.add_btn {
    background-color: #00c78c;
    color: #fff;
    border-radius: 8px;
    border: none;
}

.el-tabs {
    height: 100%;
}

.el-dialog__header {
    padding: var(--el-dialog-padding-primary);
    padding-bottom: 10px;
    border-bottom: 1px solid #dedede;
    margin-bottom: 15px;
}

.export_btn {
    background-color: #00c78c;
    color: #fff;
    border-radius: 8px;
    border: none;
}

.del_btn {
    background-color: #fff;
    color: #FF0000;
    border: none;
}
</style>